import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.pinyin.PinyinUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class ReadExcel {

    private static final Map<String, Integer> fileMap = new HashMap<>();
    public static void main(String[] args) {



        ExcelReader excelReader = ExcelUtil.getReader(new File("f://sss/专家头像.xls"));
        List<Map<String, Object>> dataList = excelReader.readAll();
        for (Map<String, Object> data : dataList) {
            File file = new File("f://sss/img/"+data.get("name_cn")+".png");
            if (!file.exists()) {
                file = new File("f://sss/img/"+data.get("name_en")+".png");
            }
            FileUtil.copy(file,
                    new File(data.get("head_solid_pic").toString().replace("https://file.zhuyitai.com/", "f://sss/")), true);
            System.out.println("update expert set head_solid_pic = '"+ data.get("head_solid_pic")+"' where expert_id = '"+ data.get("expert_id") +"';");
        }
    }

    public static void readExcel() {
        String filePath = "C:\\Users\\Administrator\\Desktop\\抠图（第一批）";
        getFiles(filePath);
        for (Map.Entry<String, Integer> kv : fileMap.entrySet()) {
            if (kv.getValue() == 1 && !kv.getKey().contains("图层")) {
                System.out.println(kv.getKey().replaceAll(".png", ""));
//				System.out.println(kv.getValue().toString().replaceAll("//", "/").replace(filePath, "").replace("\\", "/"));
            }
        }
    }

    public static void getFiles(String filePath) {

        File fileAll = new File(filePath);

        File[] files = fileAll.listFiles();

        for (File file : files) {
            if (file.isDirectory()) {
                //如果是目录
                //递归
                getFiles(file.getAbsolutePath());
            } else {
                if (!fileMap.containsKey(file.getName())) {
                    fileMap.put(file.getName(), 1);
                } else {
                    fileMap.put(file.getName(), fileMap.get(file.getName()) + 1);
                }

            }

        }

    }
}
